#ifndef PROC_H
#define PROC_H

#include "list.h"

/*
 * Process control block
 *
 *   link  - list node element linking pcb's. *must* be the first element
 *   pid   - unique process id assigned at process creation
 *   prio  - process priority assigned at process creation
 *   state - process state (of the form SCHED_XXXX)
 *   timer - multi-purpose timer:
 *           for SCHED_RUNNING processes, it is the time quantum remaining
 *           for SCHED_SLEEP_WAIT processes, it is the sleep time remaining
 *   tsize - size of the process' text (code)
 *   ptr   - pointer into the text array of the instruction to be executed next
 *   text  - variable length array. contains the process' text (code)
 */
typedef struct proc_t {
    node   link;
    int    pid;
    int    prio;
    int    timer;
    int    state;
    char  *ptr;
    int    tsize;
    char   text[];
} proc;


/*
 * Process instruction types
 *
 *   PROC_CPU   - generic user-space cpu execution instruction
 *   PROC_SLEEP - process sleep instruction. voluntarily yields cpu.
 *   PROC_EXEC  - spawn new process and load instructions from a specified file
 */
enum {
    PROC_CPU,
    PROC_SLEEP,
    PROC_EXEC,
    PROC_UNDEF
};


/*
 * proc_cpu(proc *p)
 *
 *
 */
int proc_cpu(proc *p);
int proc_exec(proc *p, char *prog, int prio);
int proc_sleep(proc *p, int duration);
int proc_execute(proc *p);

#endif
